<?php
/**
 * @version $Id: Regex.php 181 2008-03-11 21:46:28Z mikhail.miguel $
 */

require_once dirname(dirname(dirname(dirname(__FILE__)))).'/lib/trackback/spamcheck.php';

class SpamCheck_Regex extends SpamCheck {
    var $_options = array(
        'sources'       => array(
            '(acne|adipex|anal|blackjack|cash|casino)',
        ),
        'elements'      => array(
            'title',
            'excerpt',
            'blog_name',
            'url'
        )
    );

    function SpamCheck_Regex($options=null)
    {
        if (is_array($options)) {
            foreach ($options as $key => $val) {
                $this->_options[$key] = $val;
            }
        }
    }

    function _checkSource(&$source, $trackback)
    {
        $spam = false;
        foreach ($this->_options['elements'] as $element) {
            if(TrackbackService::isError($item = $trackback->get($element))) {
                return TrackbackService::setError($item->getMessage().'<br />'.' Cannot procede without it.');
            }
            $elements[$element] = $item;
        }
        foreach ($elements as $element) {
            if (0 !== preg_match('/'. $source. '/i', $element)) {
                return TrackbackService::setError('Your trackback contains our banned word.');
            }
        }
        return true;
    }
}
?>